package com.hymjweb.demo.hymj.basic_data_manage.xt_airlines.add_cost_detail.controller;

import com.hymjweb.demo.framework.result.BaseResultMap;
import com.hymjweb.demo.framework.sys.BaseController;
import com.hymjweb.demo.framework.sys.SysConstant;
import com.hymjweb.demo.framework.util.DataTypeUtil;
import com.hymjweb.demo.hymj.basic_data_manage.xt_airlines.add_cost_detail.bean.XtAirlinesAddCostDetailPojo;
import com.hymjweb.demo.hymj.basic_data_manage.xt_airlines.add_cost_detail.service.XtAirlinesAddCostDetailService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/pages/basic_data_manage/xt_airlines/add_cost_detail")
public class XtAirlinesAddCostDetailController extends BaseController {

    @Autowired
    private XtAirlinesAddCostDetailService xtAirlinesAddCostDetailService;

    @RequestMapping("/init")
    public String init(HttpServletRequest request) {
        return "pages/basic_data_manage/xt_airlines/add_cost_detail/xtairlinesaddcostdetail";
    }

    @RequestMapping("/query")
    @ResponseBody
    public Object query(@RequestParam(required = false) Map param) throws Exception {
        if(param == null || param.isEmpty()){
            throwException("附加费查询参数错误!");
        }
        return xtAirlinesAddCostDetailService.getPageList(param);
    }

    @RequestMapping("/queryAddCostDetailListByAirlinesId")
    @ResponseBody
    public List<XtAirlinesAddCostDetailPojo> queryAddCostDetailListByAirlinesId(String airlinesId) throws Exception {
        return xtAirlinesAddCostDetailService.queryAddCostDetailListByAirlinesId(airlinesId);
    }

    @RequestMapping("/insert")
    @ResponseBody
    public Object insert(@RequestBody(required = true) XtAirlinesAddCostDetailPojo xtAirlinesAddCostDetailPojo) throws Exception {
        if(xtAirlinesAddCostDetailPojo == null){
            throwException("保存附加费参数错误!");
        }
        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("保存附加费成功!");
        int affectRow = xtAirlinesAddCostDetailService.insertInit(xtAirlinesAddCostDetailPojo);
        if (affectRow <= SysConstant.INT_ZERO) {
            baseResultMap.setOk(false);
            baseResultMap.setMessage("保存附加费失败!");
        }
        return baseResultMap;
    }

    @RequestMapping("/update")
    @ResponseBody
    public Object update(@RequestBody(required = true) XtAirlinesAddCostDetailPojo xtAirlinesAddCostDetailPojo) throws Exception {
        if(xtAirlinesAddCostDetailPojo==null){
            throwException("更新附加费参数错误!");
        }

        int affectRow = xtAirlinesAddCostDetailService.updateInit(xtAirlinesAddCostDetailPojo);
        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("更新附加费成功!");

        if (affectRow <= SysConstant.INT_ZERO) {
            baseResultMap.setOk(false);
            baseResultMap.setMessage("更新附加费失败!");
        }
        return baseResultMap;
    }

    @RequestMapping("/delete")
    @ResponseBody
    public Object delete(@RequestBody(required = true) String id) throws Exception {
        if(DataTypeUtil.isEmptyStr(id)){
            throwException("附加费删除参数错误!");
        }
        int affectRow = xtAirlinesAddCostDetailService.delete(id);
        BaseResultMap baseResultMap = new BaseResultMap();
        baseResultMap.setOk(true);
        baseResultMap.setMessage("删除附加费成功!");
        if (affectRow <= SysConstant.INT_ZERO) {
            baseResultMap.setOk(false);
            baseResultMap.setMessage("删除附加费失败!");
        }
        return baseResultMap;
    }

}
